<?php

/*
 * This file will query all of the security group.
 * This is used by: admCreatePos.php
 * 
 * Created by: Peter Agno Jr.
 * Date created: November 27, 2011
 * 
 * In parameters :
 * Out parameters : Array of securityGroupId and securityGroupName
 */

    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
    include('../includes/siteConfig.php');
    
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');

    $query = 
        "
            SELECT * 
            FROM SecurityGroup 
            ORDER BY securityGroupName
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

    if ( mysql_num_rows($result) > 0 ) {
        while ($row = mysql_fetch_array($result)) {
            $jsondata = array();
            $jsondata['securityGroupId'] = $row['securityGroupId'];
            $jsondata['securityGroupName'] = $row['securityGroupName'];
            $feed[] = $jsondata;
        }
        
        echo json_encode($feed);
    }
    else {
        echo json_encode(0);
    }
    
    mysql_free_result($result);
    mysql_close($connect);
?>
